package com.example.backend.service;

import com.example.backend.entity.User;
import com.example.backend.mapper.UserMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 用户表服务类
 */
@Service
public class UserService {
    private UserMapper userMapper;

    @Autowired
    public UserService(UserMapper userMapper){
        this.userMapper=userMapper;
    }

    /**
     * 用户登录功能
     * @param username
     * @param password
     * @return
     */
    public boolean userLogin(@Param("username") String username,@Param("password") String password){
        User user=userMapper.userLogin(username,password);
        if(user==null)
            return false;
        else
            return true;
    }

    public boolean insertUser(@Param("userId") int userId,@Param("userName") String userName,@Param("password") String password,@Param("sex") int sex,@Param("age") int age,@Param("phone") String phone)
    {
        int user = userMapper.insertUser(userId,userName,password,sex,age,phone);
        if(user == 0)
            return false;
        else
            return true;
    }
}
